import { utilsServices } from ".";

let isNavigateing = false;

// 定义路由
export const navigateServices = {
  to: <T extends { [key: string]: string }>({
    url,
    data,
  }: {
    url: string;
    data?: T;
  }) => {
    uni.navigateTo({
      url: url + (data ? `?${utilsServices.getQueryStr(data)}` : ""),
    });
  },

  back: () => {
    uni.navigateBack();
  },

  switchTab: ({ url }: { url: string }) => {
    if (isNavigateing) {
      return utilsServices.showToast('您切换的太快啦~');
    }
    isNavigateing = true;
    uni.switchTab({
      url,
      complete: () => {
        isNavigateing = false;
      },
    });
  },
};
